const DoublyLinkedList = require("../template.js")

/** 6. 排序方法测试 */
function testSort() {
  const link = DoublyLinkedList.fromArray([1, 2, 3, 4])

  // 测试反转
  link.reverse()
  console.log(
    "4.1 链表反转:",
    link.head.value === 4 &&
      link.tail.value === 1 &&
      link.findByIndex(1).value === 3
  )

  // 测试查找中间节点
  const middle = link.findMiddleNode()
  console.log(
    "4.2 查找中间节点(偶数长度):",
    middle.value === 3 || middle.value === 2 // 取决于具体实现规则
  )

  const oddList = DoublyLinkedList.fromArray([1, 2, 3])
  console.log(
    "4.3 查找中间节点(奇数长度):",
    oddList.findMiddleNode().value === 2
  )
  console.log("--------------------")
}

testSort()

module.exports = testSort
